macro(conan_append_conf)
    message(STATUS "conan_append_conf -------------------------------")
    if (NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
        if (CMAKE_TOOLCHAIN_FILE)
            string(APPEND profile "tools.cmake.cmaketoolchain:user_toolchain=[\"${CMAKE_TOOLCHAIN_FILE}\"]\n")
        endif ()
        string(APPEND profile "tools.system.package_manager:mode=install\n")
        string(APPEND profile "tools.system.package_manager:sudo=True\n")
        string(APPEND profile "tools.system.package_manager:sudo_askpass=True\n")
    endif ()
endmacro()

macro(conan_append_buildenv)
    message(STATUS "conan_append_buildenv ---------------------------")
    if (NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
        set(CONAN_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${BUILD_TYPE}}")
        set(CONAN_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${BUILD_TYPE}}")
        set(CONAN_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_${BUILD_TYPE}}")

        get_filename_component(CONAN_COMPILER_ROOT_PATH "${CMAKE_C_COMPILER}" DIRECTORY)
        set(CONAN_CMAKE_C_COMPILER "${CMAKE_C_COMPILER}")
        set(CONAN_CMAKE_CXX_COMPILER "${CMAKE_CXX_COMPILER}")
        set(CONAN_CMAKE_ASM_COMPILER "${CMAKE_ASM_COMPILER}")
        set(CONAN_CMAKE_LINKER "${CMAKE_LINKER}")
        set(CONAN_CMAKE_AR "${CMAKE_AR}")
        set(CONAN_CMAKE_OBJCOPY "${CMAKE_OBJCOPY}")
        set(CONAN_CMAKE_OBJDUMP "${CMAKE_OBJDUMP}")
        set(CONAN_CMAKE_RANLIB "${CMAKE_RANLIB}")
        set(CONAN_CMAKE_STRIP "${CMAKE_STRIP}")

        string(APPEND profile "[buildenv]\n")
        string(APPEND profile "PATH=+(path)${CONAN_COMPILER_ROOT_PATH}\n")
        string(APPEND profile "CFLAGS=${CONAN_C_FLAGS}\n")
        string(APPEND profile "CXXFLAGS=${CONAN_CXX_FLAGS}\n")
        string(APPEND profile "LDFLAGS=${CONAN_LINKER_FLAGS}\n")
        string(APPEND profile "CC=${CONAN_CMAKE_C_COMPILER}\n")
        string(APPEND profile "CXX=${CONAN_CMAKE_CXX_COMPILER}\n")
        string(APPEND profile "AS=${CONAN_CMAKE_ASM_COMPILER}\n")
        string(APPEND profile "LD=${CONAN_CMAKE_LINKER}\n")
        string(APPEND profile "AR=${CONAN_CMAKE_AR}\n")
        string(APPEND profile "OBJCOPY=${CONAN_CMAKE_OBJCOPY}\n")
        string(APPEND profile "OBJDUMP=${CONAN_CMAKE_OBJDUMP}\n")
        string(APPEND profile "RANLIB=${CONAN_CMAKE_RANLIB}\n")
        string(APPEND profile "STRIP=${CONAN_CMAKE_STRIP}\n")
    endif ()
endmacro()